package com.linwen.excise.leetcode;

/**
 * @ClassName _657机器人能否返回原点
 * @Description TODO
 * @Author zero
 * @DATE 2024/9/28 6:08 PM
 * @Version 1.0
 */
public class _657机器人能否返回原点 {
    public static void main(String[] args) {
        _657机器人能否返回原点 inst = new _657机器人能否返回原点();
        String moves = "UD";
        System.out.println(inst.judgeCircle(moves));
    }

    public boolean judgeCircle(String moves) {
        int row = 0, col = 0;
        char[] charArray = moves.toCharArray();
        for (char c : charArray) {
            switch (c) {
                case 'R':
                    row++;
                    break;
                case 'L':
                    row--;
                    break;
                case 'U':
                    col++;
                    break;
                case 'D':
                    col--;
                    break;
            }
        }
        return row == col && row == 0;
    }

}
